import java.io.FileNotFoundException;
import java.util.*;

public class TestK_Label {

    public static double[] testK_Label(int K) throws FileNotFoundException {
//        int K = 22;
        Instance inst = new Instance("./data/wine_norm.csv", 4898);
//        Instance inst = new Instance("./data/winequality-white.csv", 4898);
//        inst.print_instance();

        BallTree bt = new BallTree(inst);
        int[] test_idx = new int[]{1331, 576, 2479, 1188, 4591, 4250, 4435, 3615, 2004, 918, 4540, 275, 3715, 4108, 8, 4218, 2605, 2212, 1006, 3107, 302, 221, 239, 61, 3631, 2077, 4017, 286, 4835, 2144, 4144, 4592, 2254, 3346, 2229, 2101, 4324, 2835, 203, 3972, 987, 1775, 2909, 1212, 3227, 4632, 4855, 4696, 1812, 2977, 2765, 4620, 4678, 3771, 332, 4494, 2354, 3865, 3958, 1667, 3526, 3570, 821, 4152, 4702, 1076, 1587, 3768, 3548, 4551, 298, 4420, 408, 3023, 3772, 1634, 1622, 4640, 2194, 95, 1904, 2239, 3866, 4731, 3337, 3396, 4321, 2644, 41, 3649, 4724, 1295, 1968, 4059, 515, 4499, 3498, 1905, 4675, 3945, 4525, 3424, 4792, 3348, 6, 3215, 4309, 269, 2217, 1706, 1734, 890, 2481, 313, 666, 789, 145, 4274, 123, 2744, 2427, 2639, 1090, 1770, 3339, 2840, 653, 1611, 1547, 4707, 1617, 2684, 2879, 4286, 3140, 4595, 4446, 1157, 228, 3045, 3685, 3335, 4010, 1800, 2508, 1082, 2467, 1999, 4097, 190, 2184, 60, 1897, 694, 152, 3446, 4492, 760, 2150, 3388, 2457, 3283, 2030, 2681, 4830, 1096, 4544, 4879, 3090, 3825, 3355, 2506, 4624, 1120, 2543, 3152, 129, 1879, 3264, 2819, 3850, 1551, 3201, 3091, 4597, 295, 3541, 1473, 575, 4518, 1049, 4846, 231, 1507, 337, 4085, 358, 1520, 4312, 4421, 1471, 3554, 751, 1995, 2752, 1262, 601, 30, 2740, 4172, 4051, 166, 2891, 3911, 4633, 4727, 4258, 2771, 2221, 811, 3952, 4114, 4121, 3717, 3384, 3043, 2476, 163, 1807, 990, 1670, 472, 1012, 2790, 3259, 4243, 2074, 2903, 963, 2393, 490, 4418, 3228, 1861, 1461, 2449, 2428, 59, 1575, 3009, 4133, 1917, 4251, 1392, 4859, 748, 994, 4081, 1589, 3880, 2747, 3733, 627, 1628, 2044, 1056, 1322, 3260, 458, 3998, 1810, 4382, 2690, 1657, 4304, 4188, 4426, 3336, 2609, 2351, 3651, 4868, 1181, 315, 3475, 180, 393, 617, 805, 790, 4292, 4738, 4432, 1327, 4883, 1599, 2948, 4600, 4008, 1279, 1760, 1626, 1631, 523, 1447, 1183, 4113, 2969, 4874, 3427, 4204, 2374, 628, 2836, 2698, 3663, 4482, 1550, 175, 1936, 347, 1813, 4109, 3777, 703, 3955, 569, 1635, 525, 3016, 2871, 3731, 4496, 4545, 2777, 2695, 1121, 2759, 378, 1324, 1747, 4869, 1460, 2751, 4417, 4299, 4867, 4489, 1377, 501, 4806, 224, 4512, 4698, 43, 3013, 3247, 53, 422, 1979, 527, 3943, 4196, 3784, 179, 4880, 1204, 3759, 2865, 2007, 764, 528, 4586, 796, 3308, 1210, 752, 4536, 4023, 487, 2085, 4380, 3858, 2676, 3902, 1457, 4662, 1269, 3412, 2309, 1535, 478, 1023, 3166, 1543, 4234, 108, 37, 4262, 4517, 3486, 2924, 1549, 2180, 1866, 1529, 1902, 305, 312, 1542, 2956, 2201, 513, 1258, 1069, 3755, 3026, 3706, 4200, 4351, 3338, 2264, 3214, 1716, 1296, 4708, 2668, 4182, 1511, 985, 1234, 1731, 373, 3913, 1391, 416, 3589, 2160, 419, 4181, 857, 3823, 401, 1758, 725, 3143, 2797, 2950, 4398, 2385, 1418, 603, 3077, 174, 2443, 2683, 4101, 19, 4748, 2780, 1826, 1567, 3964, 639, 2080, 184, 133, 161, 4392, 3694, 72, 2396, 4648, 1454, 2620, 177, 3520, 1501, 2712, 3156, 3757, 1588, 2198, 1578, 4548, 1472, 2868, 1947, 132, 2577, 3769, 4358, 630, 1182, 4257, 1976, 743, 2129, 4894, 3210, 3280, 4498, 1215, 2031, 1923, 3949, 3204, 3261, 2459, 3954, 198, 3040, 1672, 2519, 2572, 4466, 1124, 2312, 3732, 4828, 4533, 2357, 556, 2721, 4464, 3290, 680, 1061, 3438, 2331, 3081, 181, 2925, 241, 2047, 4832, 4154, 4001, 3882, 2460, 4379, 1113, 1102, 3217, 1544, 91, 1304, 3678, 3729, 1585, 2520, 3374, 2187, 3878, 2242, 2852, 1848, 4442, 4110, 47, 2417, 3326, 816, 3423, 3791, 1353, 2636, 331, 3049, 2303, 3831, 3763, 1307, 3254, 2567, 3063, 2258, 2200, 14, 3648, 3686, 4216, 4132, 2125, 2850, 4038, 169, 1570, 4301, 1142, 3748, 3928, 1151, 592, 3751, 193, 4520, 439, 524, 112, 2816, 103, 1906, 1714, 1847, 684, 4235, 1179, 2191, 1949, 431, 1078, 1045, 1094, 4427, 1874, 4385, 1964, 2829, 4824, 2095, 3161, 2953, 705, 137, 2058, 2430, 2186, 2613, 1205, 1776, 681, 1748, 3296, 1415, 4076, 2669, 126, 1525, 114, 2470, 940, 200, 1047, 4845, 3270, 4555, 2637, 3712, 1491, 4277, 4743, 3398, 2806, 1510, 3454, 4390, 2462, 4537, 3873, 2093, 4443, 4281, 361, 2001, 794, 1434, 271, 2039, 469, 2053, 2000, 1041, 3804, 1744, 819, 71, 3790, 208, 3961, 1465, 2877, 1118, 4836, 4215, 3292, 206, 2366, 1312, 2203, 623, 1354, 3847, 4523, 3980, 1251, 3121, 648, 4472, 1974, 3245, 3208, 113, 2104, 4131, 2500, 1909, 118, 1036, 1313, 2112, 3799, 859, 2164, 2651, 1436, 613, 2378, 3722, 4650, 3606, 3061, 3576, 1604, 407, 217, 536, 851, 1104, 1077, 1845, 2127, 803, 3282, 4812, 4617, 4184, 406, 1378, 724, 2959, 4175, 2720, 2838, 3618, 2290, 4458, 1129, 579, 2894, 246, 4756, 2353, 2627, 3451, 4178, 4226, 21, 3829, 2674, 1408, 3978, 4876, 1248, 3357, 640, 1784, 248, 167, 222, 3601, 3163, 77, 2294, 3743, 1197, 2600, 3993, 4785, 3098, 1231, 4870, 2657, 4834, 3206, 1267, 1967, 1253, 3720, 1221, 4829, 2778, 1607, 4674, 2584, 3229, 3586, 616, 1020, 3517, 3984, 1642, 738, 4104, 1852, 4706, 3915, 2981, 4655, 2992, 3679, 1044, 1668, 1553, 3327, 2980, 2990, 2392, 3343, 287, 2867, 1325, 4105, 2521, 2582, 3658, 968, 2185, 3199, 3898, 3692, 4053, 2245, 555, 2658, 3656, 2993, 661, 927, 3071, 4314, 2222, 2904, 4043, 247, 2827, 320, 1684, 3904, 3485, 3365, 3309, 2420, 3595, 957, 944, 2986, 1243, 94, 1093, 3158, 4207, 1265, 2526, 3002, 1952, 3306, 2057, 4615, 1432, 3644, 4149, 3457, 51, 2299, 3000, 778, 3035, 3244, 1110, 2615, 379, 2870, 2175, 3285, 3219, 4045, 2988, 2581, 2883, 2143, 4239, 1969, 15, 3157, 3162, 3504, 3479, 1850, 2773, 3410, 242, 1250, 3568, 973, 3202, 3318, 999, 904, 3659, 598, 1504, 845, 3291, 3062, 3174, 4337, 2803, 1336, 832, 3263, 188, 2857, 2965, 3932, 17, 3030, 1665, 1402, 3681, 836, 2333, 4332, 158, 159, 3473, 22, 4336, 1345, 2943, 3672, 3461, 1348, 948, 4212, 496, 1649, 905, 3528, 2920, 3109, 2388, 1405, 662, 3275, 189, 2401, 2532, 46, 2888, 1690, 1483, 690, 2119, 4253, 176, 178, 3933, 115, 4508, 1423, 2503, 3973, 1430, 2656, 4686, 740, 3810, 294, 1417, 820};
        int[] train_idx = new int[]{0, 1, 2, 3, 4, 5, 7, 9, 16, 18, 24, 25, 26, 27, 28, 31, 32, 33, 40, 42, 44, 48, 50, 54, 55, 56, 57, 58, 63, 64, 70, 73, 80, 81, 83, 85, 86, 87, 89, 90, 96, 99, 105, 107, 110, 116, 117, 124, 125, 136, 139, 142, 143, 144, 146, 149, 151, 154, 155, 156, 170, 171, 183, 186, 192, 195, 209, 213, 223, 226, 227, 232, 233, 234, 235, 236, 237, 243, 245, 254, 258, 260, 263, 264, 266, 268, 270, 276, 291, 299, 300, 301, 303, 304, 307, 309, 316, 319, 322, 323, 326, 327, 328, 335, 336, 341, 342, 344, 345, 348, 352, 354, 355, 356, 357, 359, 360, 362, 363, 366, 367, 368, 370, 371, 381, 382, 383, 388, 392, 397, 399, 400, 404, 410, 411, 414, 415, 418, 421, 423, 425, 426, 441, 443, 444, 447, 448, 455, 463, 466, 467, 470, 474, 477, 479, 481, 485, 486, 488, 489, 492, 493, 494, 495, 497, 500, 502, 504, 505, 508, 510, 511, 512, 517, 518, 522, 529, 530, 532, 533, 534, 537, 539, 542, 543, 544, 545, 546, 547, 557, 559, 562, 565, 566, 568, 582, 583, 585, 586, 589, 591, 597, 600, 604, 605, 609, 611, 618, 619, 622, 629, 632, 634, 635, 642, 647, 655, 656, 664, 667, 668, 670, 671, 673, 675, 676, 682, 688, 691, 696, 704, 707, 708, 711, 712, 714, 716, 722, 730, 731, 733, 735, 736, 739, 741, 742, 745, 746, 747, 749, 750, 753, 757, 761, 763, 765, 767, 775, 776, 781, 785, 786, 787, 797, 798, 800, 804, 807, 808, 809, 813, 814, 823, 825, 826, 830, 833, 834, 849, 862, 863, 865, 869, 872, 877, 878, 881, 882, 883, 884, 886, 888, 895, 896, 897, 898, 899, 901, 903, 917, 921, 922, 923, 932, 938, 941, 951, 952, 954, 959, 960, 962, 964, 966, 967, 972, 974, 976, 980, 982, 983, 986, 995, 997, 998, 1002, 1004, 1005, 1009, 1010, 1017, 1018, 1019, 1024, 1025, 1026, 1030, 1031, 1032, 1033, 1035, 1051, 1058, 1064, 1066, 1074, 1079, 1081, 1083, 1088, 1091, 1092, 1098, 1100, 1101, 1111, 1112, 1125, 1130, 1131, 1135, 1140, 1148, 1153, 1156, 1158, 1159, 1160, 1161, 1163, 1164, 1167, 1169, 1170, 1172, 1174, 1177, 1190, 1192, 1194, 1195, 1198, 1200, 1203, 1206, 1208, 1209, 1213, 1214, 1220, 1222, 1225, 1228, 1230, 1233, 1236, 1240, 1247, 1252, 1255, 1256, 1257, 1259, 1260, 1261, 1263, 1274, 1275, 1278, 1280, 1285, 1289, 1290, 1291, 1292, 1298, 1300, 1302, 1303, 1308, 1309, 1310, 1311, 1314, 1315, 1316, 1318, 1320, 1321, 1326, 1328, 1334, 1335, 1339, 1340, 1342, 1343, 1352, 1356, 1357, 1360, 1366, 1368, 1370, 1372, 1373, 1376, 1379, 1382, 1383, 1384, 1387, 1389, 1390, 1393, 1399, 1401, 1407, 1409, 1410, 1411, 1413, 1414, 1416, 1421, 1424, 1425, 1426, 1433, 1443, 1444, 1445, 1446, 1448, 1449, 1450, 1452, 1456, 1458, 1459, 1462, 1463, 1466, 1475, 1477, 1478, 1479, 1480, 1481, 1482, 1485, 1486, 1487, 1488, 1490, 1498, 1499, 1506, 1508, 1513, 1515, 1516, 1517, 1518, 1523, 1524, 1526, 1527, 1528, 1533, 1534, 1537, 1538, 1539, 1540, 1545, 1546, 1548, 1556, 1557, 1560, 1563, 1565, 1568, 1571, 1572, 1576, 1581, 1584, 1590, 1591, 1592, 1593, 1594, 1595, 1597, 1598, 1600, 1601, 1606, 1610, 1615, 1616, 1618, 1623, 1625, 1629, 1637, 1641, 1646, 1651, 1653, 1660, 1661, 1663, 1669, 1674, 1677, 1678, 1681, 1689, 1692, 1694, 1695, 1696, 1697, 1698, 1699, 1700, 1705, 1712, 1713, 1717, 1719, 1722, 1724, 1725, 1726, 1727, 1729, 1730, 1733, 1735, 1737, 1740, 1741, 1742, 1743, 1749, 1750, 1752, 1754, 1755, 1761, 1763, 1771, 1772, 1773, 1774, 1777, 1782, 1783, 1785, 1792, 1795, 1798, 1799, 1802, 1803, 1804, 1809, 1815, 1818, 1819, 1820, 1823, 1827, 1828, 1834, 1836, 1838, 1839, 1842, 1843, 1844, 1849, 1851, 1855, 1859, 1860, 1864, 1865, 1867, 1870, 1871, 1876, 1877, 1878, 1881, 1885, 1895, 1896, 1898, 1900, 1911, 1912, 1913, 1914, 1918, 1919, 1925, 1926, 1928, 1930, 1932, 1934, 1945, 1946, 1953, 1957, 1958, 1963, 1965, 1966, 1970, 1975, 1977, 1978, 1985, 1986, 1988, 1993, 1994, 1996, 1997, 1998, 2002, 2003, 2005, 2006, 2010, 2013, 2015, 2019, 2020, 2021, 2022, 2023, 2028, 2029, 2032, 2036, 2040, 2042, 2043, 2055, 2061, 2064, 2068, 2070, 2071, 2078, 2082, 2084, 2087, 2088, 2089, 2098, 2107, 2108, 2109, 2114, 2118, 2128, 2131, 2132, 2133, 2134, 2136, 2145, 2146, 2149, 2152, 2153, 2157, 2158, 2162, 2163, 2179, 2181, 2188, 2189, 2190, 2192, 2193, 2196, 2197, 2199, 2206, 2209, 2211, 2213, 2215, 2218, 2220, 2223, 2231, 2232, 2235, 2238, 2247, 2248, 2250, 2255, 2257, 2259, 2261, 2262, 2267, 2268, 2269, 2271, 2272, 2276, 2277, 2278, 2280, 2281, 2291, 2292, 2295, 2297, 2304, 2314, 2315, 2320, 2322, 2323, 2325, 2327, 2330, 2332, 2339, 2340, 2344, 2345, 2347, 2348, 2352, 2356, 2360, 2362, 2367, 2368, 2369, 2375, 2376, 2377, 2381, 2383, 2391, 2397, 2398, 2399, 2402, 2403, 2406, 2407, 2410, 2411, 2416, 2423, 2425, 2426, 2429, 2433, 2434, 2437, 2439, 2441, 2447, 2448, 2453, 2455, 2456, 2458, 2468, 2472, 2473, 2478, 2482, 2483, 2485, 2487, 2488, 2489, 2490, 2492, 2499, 2504, 2505, 2510, 2511, 2512, 2516, 2517, 2527, 2528, 2530, 2535, 2536, 2537, 2538, 2541, 2544, 2545, 2548, 2551, 2560, 2562, 2564, 2568, 2569, 2571, 2575, 2579, 2587, 2590, 2597, 2599, 2602, 2606, 2607, 2608, 2619, 2628, 2630, 2635, 2638, 2640, 2648, 2649, 2659, 2660, 2661, 2662, 2673, 2677, 2679, 2680, 2682, 2686, 2688, 2689, 2691, 2692, 2693, 2694, 2696, 2699, 2704, 2705, 2706, 2708, 2713, 2714, 2715, 2717, 2718, 2719, 2723, 2724, 2726, 2727, 2728, 2734, 2735, 2736, 2742, 2743, 2746, 2749, 2756, 2758, 2760, 2763, 2764, 2766, 2767, 2768, 2781, 2782, 2783, 2784, 2786, 2802, 2805, 2808, 2812, 2823, 2824, 2825, 2826, 2832, 2834, 2837, 2841, 2842, 2843, 2853, 2854, 2859, 2860, 2861, 2862, 2863, 2864, 2869, 2875, 2878, 2885, 2889, 2900, 2907, 2908, 2914, 2915, 2916, 2918, 2921, 2923, 2929, 2932, 2933, 2940, 2944, 2946, 2947, 2949, 2957, 2961, 2966, 2967, 2972, 2973, 2974, 2975, 2976, 2978, 2982, 2983, 2984, 2989, 2995, 2997, 3004, 3005, 3006, 3011, 3012, 3014, 3015, 3017, 3019, 3020, 3024, 3028, 3031, 3033, 3034, 3037, 3038, 3039, 3041, 3042, 3044, 3046, 3048, 3054, 3055, 3059, 3065, 3068, 3072, 3080, 3082, 3084, 3085, 3088, 3092, 3094, 3095, 3101, 3102, 3105, 3106, 3110, 3113, 3114, 3115, 3120, 3122, 3124, 3128, 3129, 3130, 3132, 3133, 3134, 3135, 3137, 3138, 3139, 3142, 3144, 3145, 3146, 3147, 3148, 3149, 3150, 3151, 3153, 3154, 3159, 3160, 3164, 3165, 3168, 3169, 3170, 3171, 3175, 3176, 3178, 3180, 3181, 3183, 3185, 3191, 3192, 3195, 3197, 3207, 3211, 3213, 3221, 3222, 3223, 3224, 3226, 3230, 3231, 3233, 3234, 3235, 3236, 3240, 3242, 3246, 3250, 3251, 3255, 3256, 3257, 3258, 3266, 3267, 3268, 3279, 3281, 3284, 3288, 3294, 3298, 3302, 3314, 3316, 3317, 3321, 3323, 3324, 3329, 3330, 3331, 3333, 3334, 3340, 3341, 3344, 3345, 3347, 3349, 3350, 3351, 3352, 3353, 3356, 3358, 3359, 3361, 3362, 3363, 3364, 3366, 3367, 3368, 3370, 3371, 3372, 3375, 3376, 3377, 3383, 3385, 3390, 3392, 3393, 3397, 3399, 3400, 3402, 3404, 3405, 3406, 3408, 3411, 3413, 3416, 3418, 3425, 3426, 3428, 3430, 3431, 3434, 3435, 3436, 3443, 3447, 3453, 3455, 3459, 3460, 3462, 3465, 3466, 3469, 3471, 3472, 3474, 3478, 3487, 3488, 3491, 3494, 3497, 3501, 3506, 3509, 3510, 3512, 3513, 3514, 3524, 3525, 3527, 3532, 3533, 3536, 3539, 3540, 3542, 3543, 3544, 3545, 3546, 3547, 3549, 3550, 3551, 3552, 3553, 3555, 3557, 3558, 3560, 3562, 3564, 3565, 3566, 3567, 3569, 3572, 3573, 3574, 3582, 3583, 3587, 3588, 3597, 3599, 3600, 3602, 3604, 3607, 3608, 3609, 3611, 3612, 3613, 3619, 3622, 3623, 3628, 3629, 3630, 3632, 3633, 3635, 3639, 3640, 3641, 3642, 3643, 3645, 3652, 3653, 3654, 3661, 3670, 3675, 3677, 3680, 3683, 3688, 3691, 3695, 3697, 3698, 3702, 3703, 3704, 3705, 3707, 3711, 3724, 3725, 3730, 3735, 3738, 3747, 3749, 3760, 3775, 3781, 3782, 3789, 3792, 3793, 3795, 3796, 3801, 3803, 3805, 3808, 3809, 3817, 3818, 3819, 3821, 3822, 3826, 3828, 3833, 3836, 3837, 3840, 3841, 3842, 3844, 3846, 3848, 3852, 3854, 3855, 3856, 3857, 3861, 3862, 3863, 3868, 3869, 3870, 3871, 3881, 3883, 3884, 3885, 3886, 3887, 3888, 3889, 3890, 3894, 3895, 3896, 3897, 3903, 3910, 3916, 3919, 3920, 3926, 3930, 3931, 3934, 3936, 3938, 3939, 3942, 3944, 3946, 3959, 3960, 3966, 3968, 3969, 3971, 3974, 3977, 3979, 3983, 3985, 3986, 3987, 3988, 3989, 3990, 3999, 4000, 4002, 4003, 4005, 4006, 4009, 4012, 4013, 4014, 4018, 4024, 4025, 4026, 4028, 4029, 4033, 4035, 4047, 4048, 4049, 4055, 4057, 4058, 4062, 4066, 4068, 4069, 4071, 4075, 4077, 4078, 4079, 4080, 4082, 4086, 4087, 4088, 4089, 4090, 4091, 4092, 4093, 4095, 4099, 4100, 4107, 4111, 4112, 4115, 4116, 4117, 4122, 4123, 4130, 4134, 4136, 4138, 4140, 4141, 4142, 4143, 4145, 4148, 4151, 4168, 4174, 4176, 4177, 4180, 4187, 4190, 4192, 4193, 4194, 4199, 4201, 4202, 4205, 4206, 4208, 4209, 4210, 4211, 4220, 4221, 4228, 4229, 4230, 4231, 4232, 4233, 4240, 4241, 4246, 4247, 4248, 4249, 4252, 4259, 4260, 4263, 4264, 4265, 4268, 4270, 4272, 4273, 4275, 4279, 4280, 4283, 4284, 4285, 4288, 4289, 4296, 4297, 4298, 4302, 4303, 4305, 4306, 4308, 4310, 4313, 4323, 4341, 4342, 4343, 4344, 4345, 4346, 4348, 4350, 4353, 4354, 4355, 4357, 4359, 4361, 4362, 4364, 4366, 4368, 4369, 4372, 4373, 4375, 4377, 4381, 4383, 4386, 4387, 4388, 4393, 4394, 4401, 4402, 4407, 4419, 4422, 4423, 4424, 4425, 4428, 4429, 4431, 4434, 4436, 4437, 4441, 4444, 4445, 4447, 4449, 4450, 4453, 4454, 4460, 4461, 4462, 4463, 4468, 4469, 4470, 4471, 4474, 4475, 4476, 4485, 4486, 4487, 4488, 4490, 4491, 4493, 4495, 4500, 4501, 4502, 4506, 4510, 4511, 4513, 4515, 4516, 4519, 4522, 4524, 4526, 4527, 4528, 4529, 4530, 4531, 4532, 4534, 4535, 4538, 4541, 4546, 4547, 4550, 4552, 4553, 4554, 4557, 4558, 4560, 4561, 4568, 4569, 4570, 4573, 4577, 4579, 4580, 4581, 4582, 4583, 4584, 4585, 4587, 4589, 4590, 4593, 4594, 4596, 4598, 4601, 4602, 4603, 4604, 4605, 4607, 4610, 4623, 4626, 4627, 4628, 4634, 4635, 4637, 4639, 4641, 4643, 4644, 4658, 4659, 4660, 4665, 4670, 4676, 4681, 4682, 4683, 4684, 4687, 4688, 4689, 4690, 4693, 4701, 4704, 4705, 4709, 4711, 4712, 4713, 4715, 4716, 4717, 4718, 4719, 4721, 4722, 4723, 4725, 4726, 4728, 4732, 4733, 4734, 4735, 4736, 4739, 4741, 4742, 4746, 4747, 4749, 4751, 4753, 4754, 4755, 4758, 4759, 4760, 4761, 4764, 4768, 4769, 4770, 4771, 4775, 4776, 4777, 4778, 4782, 4783, 4789, 4790, 4791, 4793, 4797, 4799, 4805, 4807, 4809, 4811, 4814, 4816, 4817, 4818, 4819, 4821, 4822, 4825, 4826, 4827, 4831, 4833, 4837, 4838, 4841, 4842, 4844, 4848, 4850, 4854, 4856, 4857, 4860, 4861, 4862, 4865, 4866, 4871, 4873, 4875, 4881, 4885, 4889, 4890, 4891, 4893, 4895, 4897, 4096, 4098, 4102, 10, 11, 12, 4106, 23, 4120, 4125, 4126, 4127, 4128, 34, 35, 36, 38, 39, 4135, 4137, 49, 4150, 4153, 4155, 4156, 62, 65, 67, 4163, 69, 4164, 75, 4171, 4173, 78, 79, 82, 4179, 84, 88, 4185, 4186, 4189, 4191, 100, 101, 102, 104, 4197, 106, 4198, 4203, 109, 111, 119, 120, 121, 122, 4214, 4219, 4225, 130, 134, 135, 140, 141, 4236, 4237, 4238, 4244, 4245, 153, 4254, 4255, 4256, 162, 164, 165, 168, 4269, 4271, 182, 185, 187, 4282, 191, 4287, 194, 4290, 196, 197, 199, 201, 202, 4291, 4293, 205, 4294, 4300, 210, 212, 215, 216, 218, 219, 220, 4311, 4316, 4320, 225, 229, 4325, 4326, 4327, 4328, 4329, 4330, 4331, 240, 244, 249, 252, 4349, 4352, 4356, 261, 262, 4360, 265, 267, 4363, 4365, 272, 273, 274, 4367, 4370, 277, 4371, 4374, 4376, 4378, 283, 284, 285, 4384, 292, 4391, 296, 4395, 4396, 4397, 4399, 4400, 306, 4403, 4404, 4405, 4408, 314, 4410, 317, 4415, 4416, 321, 324, 325, 329, 333, 334, 4430, 4433, 338, 4438, 343, 4439, 4440, 349, 4448, 4451, 4452, 4455, 4456, 4457, 4459, 369, 4465, 372, 4467, 4473, 4477, 4478, 4479, 4480, 4481, 387, 4484, 391, 394, 395, 396, 398, 402, 403, 4497, 405, 4504, 409, 4505, 4507, 412, 413, 4509, 417, 4514, 4521, 427, 428, 429, 430, 436, 4539, 446, 4542, 4543, 450, 451, 4549, 457, 459, 460, 461, 462, 464, 465, 4556, 468, 4565, 471, 4566, 4567, 475, 480, 4576, 482, 483, 484, 4588, 498, 503, 506, 4606, 4611, 516, 4612, 4613, 519, 520, 521, 4614, 4616, 4619, 4625, 531, 535, 538, 4636, 541, 4638, 549, 4649, 4652, 558, 561, 564, 4661, 567, 570, 4666, 572, 4669, 4671, 4672, 580, 581, 4679, 4685, 590, 593, 594, 596, 4692, 602, 4699, 4700, 606, 607, 608, 612, 614, 615, 620, 621, 624, 4720, 631, 633, 4729, 4730, 637, 638, 643, 644, 645, 4740, 4744, 4750, 657, 658, 660, 663, 665, 669, 674, 4772, 683, 685, 4780, 4781, 4784, 692, 693, 4788, 695, 697, 698, 699, 700, 4794, 4798, 706, 709, 710, 4808, 713, 4810, 717, 4813, 720, 721, 4820, 727, 728, 729, 734, 737, 744, 4843, 4849, 754, 4851, 756, 4852, 4853, 762, 4858, 766, 4864, 773, 4872, 777, 4877, 784, 4882, 4884, 792, 4888, 795, 4892, 801, 802, 806, 810, 815, 817, 818, 822, 824, 846, 847, 853, 856, 864, 870, 871, 874, 892, 902, 909, 910, 911, 912, 913, 915, 925, 926, 928, 929, 931, 933, 934, 935, 936, 937, 946, 947, 949, 950, 953, 955, 956, 965, 975, 977, 979, 984, 988, 992, 996, 1001, 1007, 1013, 1014, 1015, 1016, 1037, 1039, 1043, 1046, 1048, 1050, 1052, 1054, 1055, 1057, 1062, 1063, 1065, 1071, 1073, 1085, 1103, 1116, 1117, 1119, 1123, 1128, 4295, 1132, 1133, 1134, 1138, 1139, 1141, 1143, 1144, 1145, 1146, 1147, 1149, 1150, 1165, 1166, 1168, 1171, 1173, 1175, 1178, 1180, 1185, 1186, 1189, 1202, 1207, 1211, 1217, 1223, 1227, 1235, 1237, 1239, 1244, 1249, 1254, 1264, 1268, 1271, 1272, 1273, 1277, 1282, 1299, 1301, 1317, 1319, 1323, 1329, 1330, 1337, 1338, 1341, 1355, 1364, 1367, 1369, 1385, 1404, 1422, 1427, 1429, 1431, 1435, 1438, 1439, 1440, 1441, 1442, 1451, 1455, 1468, 1469, 1476, 1489, 1492, 1496, 1502, 1509, 1519, 1521, 1522, 1530, 1536, 1561, 1564, 1566, 1569, 1573, 1580, 1583, 1586, 1596, 1602, 1608, 1614, 1621, 1627, 1630, 1636, 1638, 1639, 1640, 1648, 1654, 1655, 1656, 1658, 1659, 1666, 1673, 1675, 1679, 1680, 1686, 1693, 1701, 1703, 1704, 1707, 1709, 1710, 1711, 1728, 1732, 1736, 1738, 1745, 1746, 1756, 1757, 1759, 1764, 1765, 1766, 1767, 1768, 1780, 1788, 1790, 1791, 1793, 1794, 1796, 1801, 1805, 1806, 1808, 1811, 1821, 1824, 1825, 1835, 1840, 1846, 1853, 1857, 1858, 1863, 1872, 1873, 1875, 1880, 1882, 1883, 1884, 1886, 1887, 1888, 1889, 1890, 1891, 1892, 1893, 1894, 1901, 1903, 1910, 1916, 1921, 1922, 1927, 1929, 1933, 1935, 1938, 1939, 1940, 1941, 1942, 1943, 1944, 1950, 1954, 1955, 1956, 1959, 1960, 1961, 1962, 1972, 1973, 1987, 1992, 2008, 2011, 2012, 2014, 2017, 2024, 2025, 2026, 2027, 2033, 2034, 2035, 2037, 2038, 2041, 2045, 2046, 2048, 2051, 2052, 2054, 2056, 2059, 2060, 2062, 2063, 2065, 2066, 2067, 2072, 2073, 2075, 2076, 2081, 2083, 2086, 2090, 2091, 2092, 2094, 2096, 2097, 2099, 2100, 2102, 2103, 2105, 2106, 2110, 2111, 2113, 2115, 2117, 2120, 2122, 2123, 2126, 2130, 2135, 2137, 2138, 2139, 2140, 2141, 2142, 2147, 2148, 2151, 2155, 2165, 2166, 2172, 2173, 2176, 2178, 2182, 2183, 2195, 2202, 2204, 2205, 2208, 2214, 2216, 2226, 2227, 2233, 2234, 2236, 2240, 2241, 2243, 2244, 2249, 2252, 2253, 2256, 2260, 2263, 2265, 2266, 2273, 2279, 2282, 2283, 2284, 2285, 2286, 2287, 2288, 2301, 2302, 2306, 2307, 2308, 2310, 2317, 2321, 2324, 2326, 2328, 2329, 2334, 2335, 2336, 2338, 2341, 2343, 2349, 2350, 2358, 2359, 2361, 2363, 2364, 2365, 2371, 2394, 2395, 2404, 2405, 2408, 2415, 2418, 2419, 2421, 2422, 2424, 2431, 2432, 2436, 2438, 2440, 2442, 2444, 2445, 2446, 2450, 2451, 2454, 2461, 2464, 2465, 2466, 2469, 2475, 2480, 2484, 2486, 2491, 2495, 2496, 2497, 2498, 2501, 2509, 2513, 2523, 2524, 2529, 2533, 2539, 2540, 2542, 2546, 2547, 2549, 2550, 2552, 2556, 2559, 2561, 2563, 2565, 2570, 2573, 2574, 2576, 2580, 2592, 2593, 2595, 2596, 2598, 2601, 2610, 2611, 2614, 2621, 2624, 2625, 2629, 2632, 2633, 2634, 2641, 2642, 2643, 2647, 2650, 2653, 2654, 2655, 2665, 2678, 2687, 2697, 2701, 2702, 2703, 2707, 2709, 2710, 2711, 2716, 2725, 2730, 2731, 2732, 2738, 2741, 2754, 2755, 2757, 2761, 2762, 2769, 2779, 2785, 2787, 2788, 2789, 2791, 2792, 2794, 2800, 2801, 2807, 2811, 2815, 2820, 2821, 2822, 2830, 2831, 2844, 2847, 2848, 2849, 2851, 2876, 2880, 2882, 2886, 2887, 2892, 2895, 2896, 2897, 2898, 2899, 2902, 2905, 2906, 2910, 2911, 2913, 2919, 2934, 2936, 2937, 2941, 2942, 2951, 2952, 2955, 2958, 2962, 2964, 2968, 2970, 2971, 3010, 3022, 3027, 3032, 3036, 3047, 3051, 3053, 3056, 3057, 3058, 3060, 3064, 3066, 3073, 3074, 3076, 3078, 3079, 3097, 3104, 3108, 3112, 3119, 3123, 3125, 3127, 3131, 3136, 3177, 3182, 3189, 3193, 3194, 3209, 3212, 3216, 3220, 3232, 3238, 3269, 3274, 3278, 3289, 3295, 3297, 3300, 3319, 3320, 3328, 3342, 3379, 3387, 3394, 3395, 3401, 3403, 3407, 3420, 3429, 3432, 3437, 3439, 3440, 3441, 3444, 3452, 3456, 3464, 3467, 3481, 3502, 3508, 3518, 3522, 3523, 3530, 3531, 3534, 3535, 3537, 3561, 3563, 3580, 3591, 3605, 3610, 3614, 3616, 3617, 3625, 3626, 3627, 3668, 3674, 3687, 3699, 3700, 3701, 3708, 3709, 3710, 3713, 3716, 3718, 3719, 3721, 3734, 3737, 3746, 3752, 3753, 3756, 3758, 3762, 3765, 3766, 3767, 3773, 3774, 3776, 3780, 3783, 3786, 3787, 3788, 3794, 3797, 3798, 3800, 3802, 3806, 3807, 3811, 3812, 3813, 3814, 3816, 3820, 3827, 3832, 3834, 3835, 3838, 3839, 3845, 3849, 3859, 3860, 3867, 3874, 3876, 3877, 3891, 3892, 3893, 3899, 3900, 3917, 3921, 3923, 3924, 3925, 3927, 3929, 3935, 3937, 3940, 3941, 3948, 3950, 3951, 3956, 3957, 3991, 3995, 4007, 4015, 4016, 4019, 4021, 4022, 4027, 4030, 4031, 4032, 4034, 4036, 4037, 4040, 4041, 4052, 4056, 4060, 4061, 4063, 4064, 4067, 4070, 4073, 4083, 2049, 4103, 13, 2069, 4119, 4124, 29, 4129, 4139, 45, 4146, 52, 4147, 4157, 4158, 4159, 4160, 4161, 66, 4162, 4165, 4166, 2121, 4169, 4170, 76, 2124, 4183, 92, 93, 97, 2161, 2167, 2168, 2169, 2170, 2171, 2174, 127, 128, 2177, 131, 4224, 4227, 138, 4242, 148, 150, 157, 2207, 160, 2210, 4261, 4266, 2219, 4267, 173, 2224, 2228, 4276, 2230, 2251, 211, 4307, 214, 4315, 4317, 2270, 4318, 4319, 2274, 4322, 238, 2289, 2293, 2296, 2300, 4347, 256, 257, 2305, 2311, 2313, 2316, 2319, 279, 288, 289, 290, 293, 297, 2355, 308, 310, 4406, 4409, 4411, 4412, 4413, 318, 4414, 2370, 339, 340, 346, 350, 351, 353, 364, 365, 374, 375, 376, 377, 380, 384, 385, 386, 389, 390, 2452, 4503, 2463, 420, 2471, 424, 2474, 2477, 432, 435, 438, 440, 449, 452, 453, 454, 456, 2507, 4559, 2514, 2515, 4562, 4563, 2518, 4564, 473, 4571, 476, 4572, 4574, 4575, 4578, 2534, 491, 4599, 2553, 2554, 507, 2555, 509, 2557, 2558, 4608, 514, 2566, 4618, 4621, 4622, 2578, 2583, 2585, 2586, 4629, 2588, 4630, 4631, 2591, 2594, 4642, 548, 4645, 550, 551, 552, 553, 554, 2603, 2604, 4646, 560, 4651, 4653, 563, 2612, 4654, 2616, 2617, 2618, 571, 4663, 573, 574, 2622, 2623, 577, 578, 2626, 4673, 2631, 584, 4677, 587, 588, 595, 4691, 2645, 2646, 599, 4664, 4694, 4695, 4697, 2652, 4703, 4710, 2664, 2666, 2667, 4714, 2670, 2671, 2672, 2675, 636, 2685, 4737, 649, 650, 651, 652, 2700, 654, 4752, 4757, 4762, 4763, 4767, 2722, 677, 678, 679, 4773, 2729, 2733, 686, 689, 2737, 2739, 2745, 4795, 4796, 701, 4800, 4801, 4803, 715, 718, 719, 4815, 2770, 2772, 726, 4823, 732, 4840, 2793, 2796, 2798, 2799, 4847, 755, 758, 759, 2809, 2810, 2813, 2814, 4863, 768, 769, 770, 771, 772, 2817, 2828, 782, 2833, 788, 791, 2839, 793, 4886, 4887, 2845, 2846, 4896, 2855, 2856, 2858, 812, 2866, 2872, 2874, 828, 829, 2881, 2884, 839, 840, 841, 842, 843, 2893, 848, 850, 852, 2901, 854, 855, 4647, 858, 861, 2912, 866, 868, 2917, 875, 2927, 880, 2928, 885, 887, 889, 891, 893, 894, 4656, 900, 4657, 2954, 2960, 2963, 916, 919, 920, 930, 2979, 2985, 939, 2987, 942, 943, 945, 2991, 2994, 2998, 2999, 3001, 3003, 958, 3007, 3008, 961, 4667, 4668, 969, 970, 971, 3025, 978, 981, 989, 1000, 1003, 3052, 1008, 1011, 1021, 3075, 1028, 3083, 1038, 3086, 3089, 3093, 3096, 3099, 3100, 3103, 1060, 3111, 1067, 1068, 3116, 1070, 3117, 1072, 3118, 1075, 3126, 1080, 1084, 1089, 3141, 1097, 1099, 1105, 1107, 1108, 3155, 3167, 1122, 1126, 1127, 3184, 3187, 3190, 3196, 3198, 3200, 3203, 3205, 1162, 1176, 3225, 1184, 3237, 1191, 3239, 1193, 3241, 3243, 1196, 1199, 3248, 1201, 3249, 3262, 3271, 1224, 3272, 1226, 3273, 3277, 1232, 1238, 3286, 3287, 1241, 1242, 3293, 1246, 3299, 3303, 3304, 3305, 3310, 3311, 3312, 3313, 3315, 1270, 3322, 1276, 3325, 1281, 1284, 3332, 1286, 1287, 1288, 1297, 1305, 3354, 3360, 3369, 3373, 1332, 3380, 3381, 3382, 3389, 1346, 1347, 1350, 1351, 1359, 1361, 1362, 1365, 3414, 3415, 1371, 3419, 1374, 1375, 1380, 1381, 3433, 1386, 1388, 1394, 1395, 1396, 1397, 1398, 3442, 1400, 3448, 3450, 3458, 3463, 1419, 1428, 3477, 3483, 1437, 3490, 3492, 3493, 3495, 3496, 3499, 3500, 1453, 3503, 3505, 3507, 3511, 1467, 3515, 3516, 1470, 3519, 3521, 3529, 3538, 1495, 1497, 1500, 1503, 1505, 3556, 1512, 1514, 3575, 3577, 1531, 1532, 3579, 3581, 3584, 3585, 3590, 3592, 3593, 3594, 3596, 3598, 1552, 1554, 1555, 3603, 1562, 3620, 3621, 3624, 1582, 3634, 3636, 3637, 3638, 3646, 3647, 1603, 3655, 1609, 1612, 1613, 3666, 1620, 3669, 3671, 1624, 3673, 3676, 1633, 3682, 3684, 1643, 1644, 1645, 3690, 1647, 3693, 1650, 3696, 1662, 1671, 3723, 1676, 3726, 3727, 3728, 1682, 1683, 1685, 1687, 1691, 3739, 3740, 3741, 3742, 3744, 3745, 3750, 3761, 1720, 1721, 3778, 3779, 3785, 1751, 1753, 1762, 3815, 1769, 3824, 3830, 1786, 1787, 1789, 3843, 3851, 3853, 1814, 1816, 3864, 1822, 3875, 1829, 1830, 1831, 1832, 1833, 1837, 1841, 1854, 3905, 3906, 3907, 3908, 3909, 1862, 3912, 3914, 1868, 1869, 3918, 3922, 1899, 3947, 3953, 1907, 1908, 3962, 1915, 3963, 1920, 3970, 3975, 3976, 3981, 3982, 1937, 3992, 3994, 1948, 3996, 3997, 4004, 4011, 1971, 1989, 4042, 4044, 4046, 4050, 4054, 2009, 2016, 2018, 4072, 4094, 20, 4118, 1086, 1087, 68, 1095, 4167, 3657, 74, 3660, 3664, 3665, 1106, 1619, 3667, 3070, 1115, 1632, 610, 4195, 3172, 3173, 2663, 3689, 1136, 625, 1137, 3188, 4765, 672, 4766, 1187, 3754, 4786, 1715, 3252, 3253, 3764, 4787, 1723, 2748, 2750, 1216, 2753, 1218, 1219, 4802, 3276, 723, 2774, 2775, 2776, 3301, 2795, 4333, 4334, 4335, 1266, 1778, 1779, 2804, 4338, 4339, 4340, 2298, 255, 1283, 1797, 779, 783, 280, 281, 1306, 799, 2342, 3378, 1333, 311, 2873, 3386, 3391, 1344, 835, 837, 838, 330, 2890, 844, 1358, 2382, 2384, 2389, 2390, 860, 3421, 3422, 867, 2922, 2926, 879, 2930, 2931, 3445, 3449, 1403, 2938, 2939, 1406, 2945, 1412, 907, 3468, 3470, 3476, 3480, 3482, 924, 3484, 3489, 434, 2996, 437, 1464, 442, 1980, 1981, 1982, 1983, 1984, 1991, 3018, 1493, 1494, 3029, 2522, 2525, 4065, 4084, 3069, 1022, 4609, 1027, 1029, 1541, 526, 1040, 1042, 1558, 1559, 540, 1053, 2589, 2079, 1059, 1574, 1577, 1579, 3650, 2116, 4680, 3662, 1109, 1114, 98, 2154, 3179, 2156, 2159, 626, 1652, 3186, 4213, 4217, 4222, 4223, 1152, 641, 1154, 1155, 1664, 3714, 646, 3218, 147, 659, 3736, 1702, 4774, 4779, 172, 1708, 687, 2225, 1718, 4278, 3770, 702, 2237, 4804, 2246, 1739, 204, 207, 1245, 2275, 230, 4839, 1781, 250, 2818, 259, 780, 1293, 1294, 2318, 4878, 278, 1817, 282, 3872, 2337, 4389, 3879, 2346, 3901, 831, 1856, 2372, 1349, 2379, 2380, 2386, 1363, 2387, 3417, 2400, 2409, 2412, 2413, 2414, 2935, 3965, 3967, 2435, 1924, 4483, 906, 908, 1420, 914, 1951, 433, 4020, 2493, 2494, 1474, 1990, 2502, 4039, 3021, 991, 993, 2531, 3559, 3050, 4074, 499, 3571, 3578, 3067, 3265, 2050, 2373, 1034, 1931, 4745, 1484, 1229, 3087, 3409, 1688, 873, 3307, 253, 251, 445, 827, 876, 1605, 774};
        //train_idx_arr是训练集的样本序号
        ArrayList<Integer> train_idx_arr = new ArrayList<Integer>(train_idx.length);
        for (int i : train_idx) {
            train_idx_arr.add(Integer.valueOf(i));
        }
        bt.root = bt.construct_balltree(train_idx_arr);

        //test_y的每个元素都是K个邻居，存了所有测试样本的邻居
        ArrayList<int[]> test_y = new ArrayList<int[]>();
        //test_idx是测试集的样本序号
        for (int i = 0; i < test_idx.length; i++) {
            KNN knn = new KNN();
            int[] a = knn.knnSearch(test_idx[i], K, bt);
//            for (int j = 0; j < a.length; j++) {
//                System.out.println(a[j]);
//            }
//            System.out.println("========");
            test_y.add(a);
        }

        //flag[1] 第1个样本预测是否正确
        int[] flag = new int[test_y.size()];
        for (int i = 0; i < test_y.size(); i++) {
//            System.out.println("*****"+test_idx[i]+"*****\n"+"Real: "+inst.y[test_idx[i]]);
            int[] nbs = new int[K];
            for (int j = 0; j < K; j++) {
                nbs[j] = inst.y[test_y.get(i)[j]];
//                System.out.print("Pred: "+inst.y[test_y.get(i)[j]]+", ");//打印每个邻居的真实结果
            }
            int pre_label = find_most(nbs);
//            System.out.println(test_idx[i]+","+pre_label);//打印每个测试样本的预测值
            if (pre_label == inst.y[test_idx[i]]) {
                flag[i] = 1;//正确
            } else {
                flag[i] = 0;
            }
        }
        double corr_rate = cal_corr_rate(flag);
//        System.out.println("总的正确率："+corr_rate);
        System.out.print(corr_rate);


        double[] corr_rate_label = cal_corr_rate_label(inst, flag, test_idx);
        //计算每类数据的计算正确度，然后查看每类数据的预测情况的图形
        int[] label = new int[]{3, 4, 5, 6, 7, 8, 9};
        for (int i = 0; i < corr_rate_label.length; i++) {
//            System.out.println("类别"+(label[i])+"的正确率: "+(corr_rate_label[i]));
            System.out.print(",");
            System.out.print((corr_rate_label[i]));
        }
        System.out.println();

        double[] corr_all = new double[corr_rate_label.length + 1];
        corr_all[0] = corr_rate;
        for (int i = 1; i < corr_all.length; i++) {
            corr_all[i] = corr_rate_label[i - 1];
        }
        return corr_all;
    }

    //flag[0]表示第0个样本是否预测正确，但在原数据集中index是1331
    public static double[] cal_corr_rate_label(Instance inst, int[] flag, int[] test_idx) {
        int[] label = new int[]{3, 4, 5, 6, 7, 8, 9};
        double[] corr_rate_label = new double[label.length];
        //将每个类别得到，作为ArrayList<Integer>输入
        for (int i = 0; i < label.length; i++) {
            ArrayList<Integer> flag_split_by_label = new ArrayList<Integer>();
            for (int j = 0; j < flag.length; j++) {
                int flag_j_label = inst.y[test_idx[j]];
                int label_i = label[i];
                if (flag_j_label == label_i) {
                    flag_split_by_label.add(flag[j]);
                }
            }
//            System.out.println("****"+label[i]+"****");
//            for (int j = 0; j < flag_split_by_label.size(); j++) {
//                System.out.println(flag_split_by_label.get(j));
//            }
            corr_rate_label[i] = cal_corr_rate(flag_split_by_label);
        }
        return corr_rate_label;
    }

    public static int find_most(int[] array) // 找出数组中出现次数最多的那个数
    {
        // map的key存放数组中的数字，value存放该数字出现的次数
        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
        for (int i = 0; i < array.length; i++) {
            if (map.containsKey(array[i])) {
                int formerValue = map.get(array[i]);
                map.put(array[i], formerValue + 1);    // 该数字出现的次数加1
            } else {
                map.put(array[i], 1);    // 该数字第一次出现
            }
        }
        Collection<Integer> count = map.values();
        // 找出map的value中最大值，也就是数组中出现最多的数字所出现的次数
        int maxCount = Collections.max(count);
        int maxNumber = 0;
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            //得到value为maxCount的key，也就是数组中出现次数最多的数字
            if (entry.getValue() == maxCount) {
                maxNumber = entry.getKey();
            }
        }
        return maxNumber;
//        System.out.println("该数字一共出现" + maxCount + "次");
    }

    public static double cal_corr_rate(int[] flag) {
        int corr_num = 0;
        for (int i = 0; i < flag.length; i++) {
//            System.out.println( flag[i]);
            corr_num += flag[i];
        }
        return ((double) corr_num / flag.length);//未标准化0.45565749235474007
    }

    public static double cal_corr_rate(ArrayList<Integer> flag) {
        int corr_num = 0;
        for (int i = 0; i < flag.size(); i++) {
//            System.out.println( flag[i]);
            corr_num += flag.get(i);
        }
        return ((double) corr_num / flag.size());//未标准化0.45565749235474007
    }

}

